﻿<template>
  <div class="dashboard">
    <section class="dashboard-hero">
      <h1>欢迎使用 ${projectName} 管理系统</h1>
      <p>请选择需要管理的实体开始工作。</p>
    </section>

    <section class="dashboard-entities">
      <el-row :gutter="20">
        <el-col
          v-for="entity in entities"
          :key="entity.tableName"
          :xs="24"
          :sm="12"
          :md="8"
          :lg="6"
        >
          <el-card shadow="hover" class="entity-card" @click="navigateToEntity(entity.tableName)">
            <div class="card-content">
              <div class="entity-icon">
                <el-icon size="32">
                  <Grid />
                </el-icon>
              </div>
              <div class="entity-info">
                <h3>{{ entity.displayName }}</h3>
                <p v-if="entity.tableComment">{{ entity.tableComment }}</p>
                <div class="entity-meta">
                  <span>表名：{{ entity.tableName }}</span>
                  <span>字段数：{{ entity.fields.length }}</span>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </section>

    <section class="dashboard-footer">
      <el-alert title="使用说明" type="info" :closable="false" show-icon>
        <template #default>
          <p>1. 点击上方卡片进入对应实体的管理页面。</p>
          <p>2. 支持查询、新增、编辑、删除等常规操作。</p>
          <p>3. 实体配置可在 src/config/entities.ts 中修改。</p>
        </template>
      </el-alert>
    </section>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { Grid } from '@element-plus/icons-vue'
import { entities } from '@/config/entities'

const router = useRouter()

function navigateToEntity(tableName: string) {
  router.push({ name: 'EntityView', params: { tableName } })
}
</script>

<style scoped>
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
}

.dashboard-hero {
  padding: 32px;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e4e7ed;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}

.dashboard-hero h1 {
  margin: 0 0 12px 0;
  font-size: 24px;
  color: #1f2937;
}

.dashboard-hero p {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
}

.entity-card {
  cursor: pointer;
  margin-bottom: 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.entity-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.card-content {
  display: flex;
  gap: 16px;
}

.entity-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(76, 110, 245, 0.12);
  color: #2f54eb;
}

.entity-info {
  flex: 1;
  min-width: 0;
}

.entity-info h3 {
  margin: 0 0 6px 0;
  font-size: 18px;
  color: #1f2937;
}

.entity-info p {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: #6b7280;
}

.entity-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
}

.dashboard-footer {
  margin-top: 12px;
}

.dashboard-footer :deep(.el-alert__content) {
  line-height: 1.6;
}
</style>
